#include <iostream>
#include "../comm/httplib.h"
#include "oj_control.hpp"
using namespace httplib;
using namespace ns_control;

int main()
{
    Server svr;
    Control ctl;
    // 获取所有题目列表
    svr.Get("/all_questions", [&ctl](const Request &req, Response &res)
            {
        //形成包含所有题目的html
        std::string html;
        ctl.AllQuestions(&html);
        res.set_content(html,"text/html; charset=utf-8"); });
    // 获取某一题目详情
    svr.Get(R"(/question/(\d+))", [&ctl](const Request &req, Response &res)
            {
        std::string html;
        std::string number=req.matches[1];
        ctl.OneQuestion(number,&html);
        res.set_content(html,"text/html; charset=utf-8"); });
    //判题功能
    svr.Post(R"(/judge/(\d+))",[&ctl](const Request &req,Response &res){
        std::string number=req.matches[1];
        std::string out_json;
        ctl.Judge(number,req.body,&out_json);
        res.set_content(out_json,"application/json;charset=utf-8");
    });
    svr.set_base_dir("./wwwroot");
    svr.listen("0.0.0.0", 8080);
    return 0;
}